package bma.common.langutil.jmshell.cmdopt;

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

/**
 * An option that expects a floating-point value
 */
public class DoubleOption extends Option<Double> {

	public DoubleOption(char shortForm, String longForm, String tips) {
		super(Double.class, shortForm, longForm, true, tips);
	}

	public DoubleOption(String shortForm, String longForm, String tips) {
		super(Double.class, shortForm, longForm, true, tips);
	}

	@Override
	protected Double parseValue(String arg, Locale locale)
			throws IllegalOptionValueException {
		try {
			NumberFormat format = NumberFormat.getNumberInstance(locale);
			Number num = (Number) format.parse(arg);
			return new Double(num.doubleValue());
		} catch (ParseException e) {
			throw new IllegalOptionValueException(this, arg);
		}
	}
}